﻿package mortal.game.resource.tableConfig
{
    import Message.DB.Tables.*;
    import __AS3__.vec.*;
    import com.gengine.global.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import flash.utils.*;
    import mortal.game.cache.*;
    import mortal.game.resource.info.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.GroupTowerCopy.data.*;
    import mortal.game.view.copy.towerCopy.*;
    import mortal.game.view.copy.towerCopy.other.*;

    public class TowerCopyConfig extends Object
    {
        private var _dic:Dictionary;
        private static var _instance:TowerCopyConfig;
        public static var cfgObj:Object;

        public function TowerCopyConfig()
        {
            if (_instance != null)
            {
                throw new Error(" TowerCopyConfig 单例 ");
            }
            this.init();
            return;
        }// end function

        public function init() : void
        {
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_tower_copy.json");
            if (_loc_1 == null)
            {
                _loc_1 = GroupTowerConfig.cfgObj;
            }
            cfgObj = _loc_1;
            this.write(_loc_1);
            return;
        }// end function

        private function write(param1:Object) : void
        {
            var _loc_2:TTowerCopy = null;
            var _loc_3:Object = null;
            if (!this._dic)
            {
                this._dic = new Dictionary();
            }
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new TTowerCopy();
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                this._dic[_loc_2.copyId + "_" + _loc_2.level] = _loc_2;
            }
            return;
        }// end function

        public function getInfoByID(param1:int, param2:int) : TTowerCopy
        {
            return this._dic[param1 + "_" + param2] as TTowerCopy;
        }// end function

        public function getPassConditionByID(param1:int, param2:int) : Vector.<TowerKillInfo>
        {
            var _loc_7:Array = null;
            var _loc_8:TowerKillInfo = null;
            var _loc_9:BossInfo = null;
            var _loc_3:* = new Vector.<TowerKillInfo>;
            var _loc_4:* = this.getInfoByID(param1, param2);
            var _loc_5:* = _loc_4.passCondition.split("&");
            var _loc_6:int = 0;
            while (_loc_6 < _loc_5.length)
            {
                
                _loc_7 = _loc_5[_loc_6].split("#");
                _loc_8 = new TowerKillInfo();
                _loc_9 = BossConfig.instance.getInfoByCode(int(_loc_7[0]));
                if (_loc_9 == null && Global.isDebugModle)
                {
                    Alert.show("boss表没有对应boss：" + _loc_7[0], null, Alert.OK);
                }
                if (_loc_9.category == 2 || _loc_9.category == 4)
                {
                    _loc_8.BossName = _loc_9.name;
                    _loc_8.BossNum = _loc_7[1];
                    _loc_8.BossID = int(_loc_7[0]);
                    _loc_8.bossCategory = _loc_9.category;
                    _loc_3.push(_loc_8);
                }
                _loc_6++;
            }
            return _loc_3;
        }// end function

        public function getPassRewardsByID(param1:int, param2:int) : Vector.<ItemData>
        {
            var _loc_6:Array = null;
            var _loc_8:Array = null;
            var _loc_9:ItemData = null;
            var _loc_3:* = Cache.instance.copy.tower;
            var _loc_4:* = new Vector.<ItemData>;
            var _loc_5:* = this.getInfoByID(param1, param2);
            if (_loc_3.getIsFirstKill(param1, param2) == false || _loc_3.getIsMaxLv(param1, _loc_3.getHistoryMaxLv(param1)))
            {
                _loc_6 = _loc_5.repeateRewards.split("&");
            }
            else
            {
                _loc_6 = _loc_5.rewards.split("&");
            }
            var _loc_7:int = 0;
            while (_loc_7 < _loc_6.length)
            {
                
                _loc_8 = _loc_6[_loc_7].split("#");
                _loc_9 = new ItemData(int(_loc_8[0]));
                if (_loc_3.getIsFirstKill(param1, param2) == false || _loc_3.getIsMaxLv(param1, _loc_3.getHistoryMaxLv(param1)))
                {
                    _loc_9.extData = "";
                }
                else
                {
                    _loc_9.extData = int(_loc_8[1]);
                }
                _loc_4.push(_loc_9);
                _loc_7++;
            }
            return _loc_4;
        }// end function

        public function getTowerTipInfo(param1:int, param2:int) : Object
        {
            var _loc_3:* = this.getPassConditionByID(param1, param2);
            var _loc_4:* = this.getInfoByID(param1, param2);
            var _loc_5:Object = {};
            _loc_5.power = _loc_4.advanceCombat;
            _loc_5.bossName = _loc_3[0].BossName;
            return _loc_5;
        }// end function

        public static function get instance() : TowerCopyConfig
        {
            if (_instance == null)
            {
                _instance = new TowerCopyConfig;
            }
            return _instance;
        }// end function

    }
}
